package client;


import common.DB;


public class Main{
    public static mainWindow      frame;
    private static final String[] servers        = new String[] { "127.0.0.1" };
    public static final String    feedbackServer = "127.0.0.1";
    public static final String    feedbackUrl    = "http://" + feedbackServer + "/stalker_push/feedback.php?msg=";
    public static final String    UPDATE_URL     = "http://jblink.net/stalker-notification/client.jar";
    public static final String    SERVER_JID     = "127.0.0.1";
    private static int            serverInd      = 0;
    private static Thread         botThread;
    static Boolean                isOnline       = false;
    public static String          programName    = "Stalker Notification";
    protected static String       version        = "1.00";

    public static void main(String[] args) {
        try {
            new Thread(new Runnable(){
                @Override
                public void run() {
                    common.DB.init();
                    frame = mainWindow.getMainWindow();
                    tryToLogin();
                }
            }, "MAIN_Thread").start();
            return;
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static Boolean isOnline() {

        return isOnline;
    }

    public static void tryToLogin() {

        String botNick = DB.getProp("login");
        String botPassword = DB.getProp("password");
        String botDomain = servers[serverInd];
        String botServer = servers[serverInd];
        int botPort = 5222;

        Jabber bot = new Jabber(botNick, botPassword, botDomain, botServer, botPort);
        if (botThread != null) {
            botThread.interrupt();
        }
        botThread = new Thread(bot, "1_botThread");
        botThread.start();
        Main.frame.signIn_msg.setText("");
    }

    public static void tryToLogOut() {
        botThread.interrupt();
        frame.offline();
    }
}